package com.app.qbake.module.square.activity;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.netease.nim.uikit.api.NimUIKit;
import com.wind.base.BaseActivity;
import com.wind.base.repo.ConfigRepo;
import com.wind.base.utils.DisplayUtil;
import com.wind.base.utils.Navigator;
import com.wind.data.mine.FeedbackRequest;
import com.app.qbake.R;
import com.app.qbake.module.mine.activity.FeedbackActivity;
import com.app.qbake.module.square.GoodsDetailFragment;

public class GoodsDetailActivity extends BaseActivity {

    public static void start(Context context, String goodsId) {
        Navigator.navigate(context, GoodsDetailActivity.class, goodsId);
    }
    GoodsDetailFragment fragment;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_container_with_toolbar);
        String goodsId = Navigator.getSerializableExtra(this);
        replaceFragment(fragment=GoodsDetailFragment.newInstance(goodsId));


    }


    @Override
    protected void setTitle() {
        mTitleBar.setTitle("宝贝详情");
        mTitleBar.setRightIcon(R.drawable.icon_more);
        mTitleBar.setRightClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mMenuPop!=null ){
                    mMenuPop.dismiss();
                    mMenuPop=null;
                }else {
                    showMenuPop(mTitleBar.getRightView());
                }
            }
        });
    }

    private  PopupWindow mMenuPop;
    public void showMenuPop(View view){
        if (mMenuPop==null) {
            View menuView = getLayoutInflater().inflate(R.layout.pop_menu, null);
            menuView.findViewById(R.id.tv_op1).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mMenuPop.dismiss();
                    FeedbackActivity.ExtraInfo info=new FeedbackActivity.ExtraInfo();
                    info.type= FeedbackRequest.TYPE_REPORT;
                    info.toUserId= fragment.getGoods().getUserId();
                    FeedbackActivity.start(getActivity(),info);
                }
            });
            menuView.findViewById(R.id.tv_op2).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mMenuPop.dismiss();
                    String service= ConfigRepo.getInstance().get(getActivity()).getIm_service();
                    NimUIKit.startP2PSession(getActivity(),service);
                }
            });

            mMenuPop = new PopupWindow(menuView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            mMenuPop.setOutsideTouchable(true);
            ColorDrawable drawable = new ColorDrawable(Color.TRANSPARENT);
            mMenuPop.setBackgroundDrawable(drawable);
        }
        mMenuPop.showAsDropDown(view, DisplayUtil.dip2px(getActivity(),
                50), DisplayUtil.dip2px(getActivity(),
                7));
    }

}